using MRGSP.SurveyMaster.Core.Model;
using MRGSP.SurveyMaster.Core.Repository;
using MRGSP.SurveyMaster.Core.Service;

namespace MRGSP.SurveyMaster.Service.Services
{
    public class SurveyService : ISurveyService
    {
        private readonly ISurveyRepository surveyRepo;

        public SurveyService(ISurveyRepository surveyRepo)
        {
            this.surveyRepo = surveyRepo;
        }

        public long Create(Survey survey)
        {
            return surveyRepo.Insert(survey);
        }

        public void Update(Survey survey)
        {
            surveyRepo.UpdateWhatWhere(new{survey.Name, survey.Header, survey.Footer}, new{survey.Id});
        }

        public IPageable<Survey> GetPageable(int page, int pageSize)
        {
            return surveyRepo.GetPageable(page, pageSize);
        }

        public void Delete(long id)
        {
            surveyRepo.Delete(id);
        }

        public void Activate(long id)
        {
            surveyRepo.UpdateWhatWhere(new { active = true }, new { id });
        }

        public void Deactivate(long id)
        {
            surveyRepo.UpdateWhatWhere(new {active = false}, new {id});
        }

        public Survey Get(long id)
        {
            return surveyRepo.Get(id);
        }
    }
}